package br.com.foxline.atlasmobile.dao;

import java.sql.SQLException;
import java.util.List;

import android.content.Context;
import br.com.foxline.atlasmobile.entities.AddressAux;

import com.j256.ormlite.dao.GenericRawResults;

public class AddressAuxDao extends GenericDao<AddressAux> {

	private Context context;

	public AddressAuxDao(Context context) {
		super(context, new AddressAux());
		this.context = context;
	}

	public String  getAddressByCep(String cep){
		try {
			final String sqlString = "SELECT ax.tipo_patio, ax.district FROM AddressAux ax WHERE ax.cep like "+cep+"";
			
			GenericRawResults<String[]> rawResults = getDao().queryRaw(sqlString);
			
			for (String[] strings : rawResults) {
				String tpPatio = strings[0];
				String district = strings[1];
				return tpPatio + " "+district;
			}
			
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		return "";
		
	}
	
	public boolean existReg(){
		try {
			final String sqlString = "SELECT COUNT(ax) FROM AddressAux ax";
			
			GenericRawResults<String[]> rawResults = getDao().queryRaw(
					sqlString);
			
			List<String[]> results = rawResults.getResults();
			
			if(results.isEmpty()){
				return false;
			}else{
				return true;
			}
			
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		return false;
	}
	
	
}











